Added tab completion for methods and object references to xm shell.
authorEwan Mellor <ewan@xensource.com>
Sun, 25 Feb 2007 21:52:54 +0000 (21:52 +0000)
committerEwan Mellor <ewan@xensource.com>
Sun, 25 Feb 2007 21:52:54 +0000 (21:52 +0000)
Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xend/XendAPI.py
tools/python/xen/xm/main.py

index 70bd93c99fec157f97a1b603d5f35fb067798572..5beb037a5bd5dec808366f6287b3cf9c405440d6 100644 (file)
@@ -2138,7 +2138,15 @@ class XendAPI(object):
     def debug_get_record(self, session, debug_ref):
         return xen_api_success({'uuid': debug_ref})
 
-             
+
+    def list_all_methods(self, _):
+        def _funcs():
+            return [getattr(XendAPI, x) for x in XendAPI.__dict__]
+
+        return xen_api_success([x.api for x in _funcs()
+                                if hasattr(x, 'api')])
+    list_all_methods.api = '_UNSUPPORTED_list_all_methods'
+
 
 class XendAPIAsyncProxy:
     """ A redirector for Async.Class.function calls to XendAPI
index ea52f0244d03151b00af89152b1482db4efeb648..d59d948e90c182fd2a4af49e3214c99dbbe170f3 100644 (file)
@@ -549,6 +549,10 @@ class Shell(cmd.Cmd):
     def __init__(self):
         cmd.Cmd.__init__(self)
         self.prompt = "xm> "
+        if serverType == SERVER_XEN_API:
+            res = server.xenapi._UNSUPPORTED_list_all_methods()
+            for f in res:
+                setattr(Shell, 'do_' + f, self.default)
 
     def default(self, line):
         words = shlex.split(line)
@@ -568,6 +572,16 @@ class Shell(cmd.Cmd):
                 print '*** Unknown command: %s' % words[0]
         return False
 
+    def completedefault(self, text, line, begidx, endidx):
+        cmd = line.split(' ')[0]
+        clas, func = cmd.split('.')
+        if begidx != len(cmd) + 1 or \
+           func.startswith('get_by_') or \
+           func == 'get_all':
+            return []
+        uuids = server.xenapi_request('%s.get_all' % clas, ())
+        return [u + " " for u in uuids if u.startswith(text)]
+
     def emptyline(self):
         pass